package org.xm.sk.service.data.impl;

import java.util.ArrayList;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.xm.sk.service.data.BaseService;
import org.xm.sk.service.security.XmUser;

public abstract class BaseServiceImpl<T> implements BaseService<T> {

    protected XmUser user() {
        XmUser xu = new XmUser(0, 0, 0, "anonymousUser", "匿名用户", "", "1", 1, "",
                new ArrayList<GrantedAuthority>(), null);
        try {
            Object u = SecurityContextHolder.getContext().getAuthentication()
                    .getPrincipal();
            if (u.toString().equals("anonymousUser")) {
                return xu;
            }
            return (XmUser) u;
        } catch (Exception e) {
            return xu;
        }
    }

}
